//
//  UICollectionView+RWAdditions.m
//  recyclegold-ios
//
//  Created by 81SK on 2022/4/15.
//

#import "UICollectionView+RWAdditions.h"

@implementation UICollectionView (RWAdditions)

- (void)rw_registerClass:(nullable Class)cellClass {
    
    [self registerClass:cellClass forCellWithReuseIdentifier:NSStringFromClass(cellClass)];
}

- (void)rw_registerNibClass:(nullable Class)cellClass {
    
    [self registerNib:[UINib nibWithNibName:NSStringFromClass(cellClass) bundle:nil] forCellWithReuseIdentifier:NSStringFromClass(cellClass)];
}

- (__kindof UICollectionViewCell *)rw_dequeueReusableCellWithClass:(nullable Class)cellClass
                                                   forIndexPath:(NSIndexPath *)indexPath {
    
    UICollectionViewCell *cell = [self dequeueReusableCellWithReuseIdentifier:NSStringFromClass(cellClass)
                                                                 forIndexPath:indexPath];
    
    if (indexPath && [cell respondsToSelector:NSSelectorFromString(@"setIndexPath:")]) {
        [cell setValue:indexPath forKey:@"indexPath"];
    }
    return cell;
}

- (__kindof UICollectionViewCell *)rw_loadNibCellClss:(nullable Class)cellClass owner:(nullable id)owner {
    return [[NSBundle mainBundle] loadNibNamed:NSStringFromClass(cellClass) owner:self options:nil].lastObject;
}


@end
